package com.atguigu.mapreduce.partitioner;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

public class ProvincePartitioner extends Partitioner<Text, FlowBean> {

    @Override
    public int getPartition(Text text, FlowBean flowBean, int i) {
        // text 是手机号
        String phone = text.toString();

        // 取手机号的前三位 0，1，2  (substring方法包左不包右)
        String prePhone = phone.substring(0, 3);


        //定义一个分区号变量partition,根据prePhone设置分区号
        int partaition;
        // 判断
        if ("136".equals(prePhone)) {
            partaition = 0;
        } else if ("137".equals(prePhone)) {
            partaition = 1;
        } else if ("138".equals(prePhone)) {
            partaition = 2;
        } else if ("139".equals(prePhone)) {
            partaition = 3;
        } else {
            partaition = 4;
        }

        return partaition;
    }
}
